#!/usr/bin/env python3
# -*- coding: utf8 -*-

# used coding standard: http://legacy.python.org/dev/peps/pep-0008/

# Factory method pattern


import random
from Bio import SeqUtils


class NucleoString():
    def __init__(self, sequence):
        self.sequence = sequence

    def seq(self):
        return self.sequence


class DNAString(NucleoString):
    def __init__(self, sequence):
        super().__init__(sequence)


class RNAString(NucleoString):
    def __init__(self, sequence):
        super().__init__(sequence)


# Creators

class NucleoStringCreator():
    def create_product(self):
        raise AttributeError('Not implemented')


class DNAStringCreator(NucleoStringCreator):
    alphabet = 'acgt'

    def __init__(self):
        super().__init__()


class RandomDNAStringCreator(DNAStringCreator):
    def __init__(self, length):
        super().__init__()
        self.length = length

    def create_product(self):
        return DNAString(''.join(random.choice(RandomDNAStringCreator.alphabet) for _ in range(self.length)))


class RNAStringCreator(NucleoStringCreator):
    alphabet = 'acgu'

    def __init__(self):
        super().__init__()


class FixedGCRNAStringCreator(RNAStringCreator):
    def __init__(self, gc, length):
        super().__init__()
        self.gc = gc
        self.length = length

    def _get_next_symbol(self):
        if random.random() <= self.gc:
            return random.choice('cg')
        return random.choice('au')

    def create_product(self):
        return RNAString(''.join(self._get_next_symbol() for _ in range(self.length)))


if __name__ == '__main__':
    creator = RandomDNAStringCreator(10)
    print(creator.create_product().sequence)

    creator = FixedGCRNAStringCreator(.75, 10000)
    product_sequence = creator.create_product().sequence
    print(SeqUtils.GC(product_sequence))
